import React, {Component} from 'react';
import { Router, Route, IndexRoute, Link } from 'react-router';

import Welcome from '../components/Welcome';
import Login from '../components/Account/Login';
import Register from '../components/Account/Register';
import Reset from '../components/Account/Reset';

import { requireAuthentication } from '../containers/Auth';
import { redirectAuthToHome } from '../containers/AuthToHome';

import Home from '../components/Home';
import Find from '../components/Find';
import Friends from '../components/Friends';
import Activity from '../components/Activity';
import Notification from '../components/Notification';
import Layouts from '../components/Layouts';
import Show from '../components/Profile/Show';
import Profile from '../components/Profile/Create';
import ActivityShow from '../components/Activity/Show';
import Search from '../components/Find/Search';
import Page404 from '../components/Page/404';
import About from '../components/Page/About';

export default class Routes extends Component {
  render() {
    return (
      <Router key={Math.random()} history={this.props.history}>
        <Route path="/">
          <IndexRoute component={redirectAuthToHome(Welcome)}/>
          <Route path="/login" component={redirectAuthToHome(Login)}/>
          <Route path="/register" component={redirectAuthToHome(Register)}/>
          <Route path="/reset" component={Reset}/>

          <Route path="/i" component={requireAuthentication(Layouts)}>
            <IndexRoute component={Home}/>
            <Route path="/user/:id(/:name)" component={Show}/>
            <Route path="/find(/:name)" component={Find}/>
            <Route path="/friends" component={Friends}/>
            <Route path="/activity(/:name)" component={Activity}/>
            <Route path="/activity/show/:id" component={ActivityShow}/>
            <Route path="/notifications" component={Notification}/>
            <Route path="/search/:name" component={Search}/>
          </Route>
          <Route path="/create/profile" component={requireAuthentication(Profile)}/>
          <Route path="/about" component={About}/>
          <Route path="/*" component={Page404}/>
        </Route>
      </Router>
    );
  }
};